<!--
@name:dialogConditionConfig
@author:Zhenglei
@date:10:32
@description:dialogConditionConfig
@update:2022/8/2610:32
-->
<template>
  <el-dialog title="特殊条件判断配置"
             :visible.sync="visible"
             :before-close="modalClose"
             :close-on-click-modal="false"
             :close-on-press-escape="false"
             width="50%">
    <el-form :model="subData"
             label-position="right"
             label-width="150px"
             ref="formModelRef"
             :rules='formModelRules'>
      <el-form-item label="参数：">
        <el-select v-model="subData.paramsExtra"
                   class="w-300"
                   multiple
                   clearable
                   placeholder="请选择参数">
          <el-option v-for="item in parameterDataSource"
                     :key="item.id"
                     :label="item.name"
                     :value="item.id">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="结论：">
        <el-input class="w-300" v-model="ending" placeholder="请输入结论" clearable/>
        <el-button type="primary"
                   @click="handleAdd()">新 增
        </el-button>
      </el-form-item>
      <el-form-item>
        <element-table
          :columns="columns"
          :data="subData.results">

          <template v-slot:option="{row,index}">
            <el-button type="danger"
                       @click="handleDel(index)">删除
            </el-button>
          </template>
        </element-table>

      </el-form-item>


      <el-form-item label="判断脚本：">
        <el-input class="w-300" type="textarea" autosize v-model="subData.scripts" placeholder="请输入判断脚本" clearable/>
      </el-form-item>
    </el-form>
    <p align="center">
      <el-button @click="modalClose"
                 type="info">取 消
      </el-button>
      <el-button type="primary"
                 v-prevent-re-click
                 @click="handleSave()">保 存
      </el-button>
    </p>

  </el-dialog>

</template>

<script>
import ElementTable from "../../../../../base/ElementTable";

export default {
  name: "dialogConditionConfig",
  props: {
    dataObj: {
      type: Object,
      default: {}
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      ending:'',
      subData: {
        detectionIndexId:'',
        deviceId:'',
        paramsExtra: [],
        results: [],
        scripts: '',
      },
      columns: [
        {
          label: '结论',
          prop: 'ending',
          align: 'center',
          formatter: (row, cellValue) => {
            return row
          }
        }, {
          label: '操作',
          prop: 'option',
          align: 'center',
          isSlot: true
        }
      ],

      parameterDataSource: [
        {
          id: 'age',
          name: '年龄'
        },
        {
          id: 'sex',
          name: '性别'
        },
        {
          id: 'detectType',
          name: '检测方法学'
        },
        {
          id: 'clinostatism',
          name: '检测卧位'
        },
      ],

      formModelRules: {
        indicationId: [{required: true, message: '请选择指征', trigger: 'change'},],
        sort: [{required: true, message: '请输入排序', trigger: 'blur'},],
      }
    }
  },
  created() {
    this.subData.detectionIndexId=this.dataObj.detectionIndexId
    this.subData.deviceId=this.dataObj.deviceId
    this.getDetail()
  },
  methods: {
    modalClose() {
      this.$emit('update:visible', false);
    },
    handleAdd(){
      if (!this.ending){
        this.$message.warning('请输入结论')
      }else {
        this.subData.results.push(this.ending)
        this.ending=''
      }
    },
    handleDel(index){
      this.subData.results.splice(index,1)
    },
    handleSave() {
      this.post(this.api.healthMap.saveSpecialCondition,this.subData).then((res) => {
        if (res.data.code === '200') {
          this.$message.success('保存成功')
          this.modalClose()
        }
      })
    },
    //查询详情
    getDetail() {
      this.post(this.api.healthMap.getSpecialCondition, {
        detectionIndexId: this.dataObj.detectionIndexId,
        deviceId: this.dataObj.deviceId,
      }).then((res) => {
        if (res.data.code === '200') {
          this.subData = Object.assign(this.subData,res.data.object)
        }
      })
    },
  },
  components:{
    'element-table': ElementTable,
  }
}
</script>

<style scoped>

</style>
